package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author mycp
 * 游记
 */
@Getter
@Setter
// 忽略转换成json格式的属性handler
@JsonIgnoreProperties("handler")
public class Travel extends BaseDomain {
    public static final Integer STATE_REFUSE = -1; //拒绝
    public static final Integer STATE_TEMP = 0; //草稿
    public static final Integer STATE_WAIT = 1; //待审核
    public static final Integer STATE_RELEASE = 2; //审核通过

    private String title;// 标题

    @JsonFormat(pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;// 旅游时间

    private String perExpends;// 人均消费

    private Integer days;// 旅游天数

    private Integer person;// 跟xx一起

    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createTime;// 创建时间

    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;// 发布时间

    private Boolean isPublic = false;// 是否公开--默认不公开

    private Region place;// 旅游地点

    private String coverUrl;// 封面

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastUpdateTime;// 最后更新时间

    private Integer state = STATE_TEMP;// 状态
    private User author;// 作者

    // 游记内容, 使用一对一关系
    private TravelContent travelContent;

    public String getStateName() {
        String stateName = "拒绝";
        if (STATE_TEMP.equals(state)) {
            stateName = "草稿";
        } else if (STATE_WAIT.equals(state)) {
            stateName = "待审核";
        } else if (STATE_RELEASE.equals(state)) {
            stateName = "审核通过";
        }
        return stateName;
    }


    public String getPersonName() {
        String personName = "一个人的旅行";
        if (person == 2) {
            personName = "和父母";
        } else if (person == 3) {
            personName = "和朋友";
        } else if (person == 4) {
            personName = "和同事";
        } else if (person == 5) {
            personName = "和爱人";
        } else if (person == 6) {
            personName = "和驴友";
        }
        return personName;
    }

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", getId());
        map.put("title", title);
        map.put("coverUrl", coverUrl);
        return JSONUtil.toJSONString(map);
    }

}